import 'package:flutter/material.dart';

class TextFieldAndFromRoute extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => new _TextFieldAndFromRouteState();
}

class _TextFieldAndFromRouteState extends State<TextFieldAndFromRoute> {
  //定义一个controller用于监听
  TextEditingController _unameController = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: new Text('文本框和表单'),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            TextField(
                autofocus: true,
                controller: _unameController,
                decoration: InputDecoration(
                    labelText: "用户名",
                    hintText: "用户名或邮箱",
                    prefixIcon: Icon(Icons.person)),
                onChanged: (v) {
                  //监听输入变化
                  print("onChange: $v");
                }),
            TextField(
              decoration: InputDecoration(
                  labelText: "密码",
                  hintText: "您的登录密码",
                  prefixIcon: Icon(Icons.lock)),
              obscureText: true,
            ),
            Container(
              child: TextField(
                  keyboardType: TextInputType.emailAddress,
                  decoration: InputDecoration(
                      labelText: "Email",
                      hintText: "电子邮件地址",
                      prefixIcon: Icon(Icons.email),
                      border: InputBorder.none //隐藏下划线
                      )),
              decoration: BoxDecoration(
                  // 下滑线浅灰色，宽度1像素
                  border: Border(
                      bottom: BorderSide(color: Colors.grey[200], width: 1.0))),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void initState() {
    //监听输入改变
    _unameController.addListener(() {
      print(_unameController.text);
    });
  }
}
